package com.useeinfo.oa.modules.maintaining.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.oa.common.utils.ResultUtil.ResultUtil;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.maintaining.dao.PlannerOrderLogDao;
import com.useeinfo.oa.modules.maintaining.entity.PlannerOrder;
import com.useeinfo.oa.modules.maintaining.entity.PlannerOrderLog;
import com.useeinfo.oa.modules.maintaining.enums.OrderOperationEnum;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import com.useeinfo.oa.modules.security.util.SessionKeyUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;


@Service
public class PlannerOrderLogBiz extends CrudBiz<PlannerOrderLogDao, PlannerOrderLog> {

    public void savePlannerLog(PlannerOrder plannerOrder, OrderOperationEnum orderOperationEnum,  HttpServletRequest request){
        SystemUser systemUser=SessionKeyUtils.getSessionUser(request);
        PlannerOrderLog plannerOrderLog=new PlannerOrderLog();
        plannerOrderLog.setPlannerOrder(plannerOrder);
        plannerOrderLog.setEnterprise(SessionKeyUtils.getSessionEnterprise(request));
        plannerOrderLog.setSystemUser(systemUser);
        plannerOrderLog.setUserName(systemUser.getUserName());
        String detail=systemUser.getUserName()+"在"+DateTimeUtils.formatDateToStringWithTime(new Date())+","
                +orderOperationEnum.getName()+"，操作计划工单名称为："+plannerOrder.getName()+",编号为："+plannerOrder.getId();
        plannerOrderLog.setDetail(detail);
        plannerOrderLog.setOrderOperationEnum(orderOperationEnum);
        dao.add(plannerOrderLog);
    }
}
